11. Shadowing

Shadowing

L5 23 L Variable Shadowing V3

Variable Shadowing

Without pasting into your console, what do you think this code will print out?

var x = 1;

function addTwo() {
  x = x + 2;
}

addTwo();
x = x + 1;
console.log(x);
SOLUTION: 4

Shadowing 2

Without pasting into your console, what do you think this code will print out?

var x = 1;

function addTwo() {
  var x = x + 2;
}

addTwo();
x = x + 1;
console.log(x);
SOLUTION: 2